<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>子组件向父组件发送数据</title>
</head>
<body>
<div id="app">
    {{ count }}
    <br>
    <cpn v-on:decrease="dec" v-on:increase="inc"></cpn>
</div>

<template id="cpn">
    <button v-on:click="decrease">-</button>
    <button v-on:click="increase">+</button>
</template>

<script type="module">
    import {createApp, ref} from "../../../../js/vue.esm-browser.js";
    import {defineComponent} from "../../../../js/vue.esm-browser.js";


    let cpn = defineComponent(
        {
            template: "#cpn",
            emits:["decrease", "increase"],
            setup(props, context) {

                let count = ref(0)

                function decrease() {
                    count.value -= 1
                    context.emit("decrease", count)
                }

                function increase() {
                    count.value += 1
                    context.emit("increase", count)
                }

                return {
                    decrease,
                    increase,
                };
            }
        }
    );

    let app = createApp({
        setup() {
            let count = ref(0)

            function dec(event) {
                count.value = event
            }

            function inc(event) {
                count.value = event
            }
            return {
                count,
                dec,
                inc,
            }
        },
        components:{
            cpn,
        }
    })

    app.mount("#app")
</script>
</body>
</html>